package it.kion.util.ui.ulog2.editor;

import java.util.ResourceBundle;

import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.*;
import it.kion.util.ui.ulog2.Log4jPlugin;

public class PropertiesEditor extends TextEditor
{
   private final TokenManager tokenManager;
   private final ResourceBundle resourceBundle;

   public PropertiesEditor()
   {
      super();
      tokenManager = Log4jPlugin.getDefault().getTokenManager();
      resourceBundle = Log4jPlugin.getDefault().getResourceBundle();
      setSourceViewerConfiguration(
         new PropertiesConfiguration(tokenManager));
      setDocumentProvider(new PropertiesDocumentProvider());
      setPreferenceStore(
         Log4jPlugin.getDefault().getPreferenceStore());
   }

   protected boolean affectsTextPresentation(
      PropertyChangeEvent event)
   {
      return super.affectsTextPresentation(event)
         || tokenManager.affectsTextPresentation(event);
   }

   protected void handlePreferenceStoreChanged(
      PropertyChangeEvent event)
   {
      tokenManager.handlePreferenceStoreChanged(event);
      super.handlePreferenceStoreChanged(event);
   }

   protected void createActions()
   {
      super.createActions();

      ContentAssistAction action =
         new ContentAssistAction(
            resourceBundle,
            "ContentAssistProposal.",
            this);
      action.setActionDefinitionId(
         ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
      setAction("ContentAssistProposal", action);
   }
}
